package reportcenter.enduser.ui;

//import com.tomwheeler.example.tdlfile.intf.TodoList;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.HelpCtx;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.actions.NodeAction;
import reportcenter.report.dominio.report.Report;
import reportcenter.report.support.exporter.XlsExporterExecutor;

public final class ExportXlsAction extends NodeAction {
    
    
    
    /** the main business logic of this class */
    protected void performAction(Node[] activatedNodes) {
        System.out.println("Display -> " + activatedNodes[0].getDisplayName());
        Node firstNode = activatedNodes[0];
        
        Lookup lookup = firstNode.getLookup();
        
        
//        System.out.println("OBJECT -> " + );
        
//        if (report == null) {
//            // we checked for this in enabled(Node[]), so it should not be null
//            // unless the lookup was recently changed.  But it's best to be safe.
//            System.err.println("O nó selecionado não contém objeto Report");
//            return;
//        }
        
//        new XlsExporterExecutor().executor(report);

        
        System.out.println("Funcionou!!!!!");
    }
    
    /** identifies this action (for example, in a menu) */
    public String getName() {
//        return NbBundle.getMessage(ExportXlsAction.class, "CTL_AddItem");
        return "Exportar XLS";
    }
    
    /** 
     * This identifies the icon for this action.  May or may not be shown 
     * depending on where the action is used (in a menu, toolbar, etc.)
     */
    protected String iconResource() {
        return "images/qq_medio.jpg";
    }
    
    public HelpCtx getHelpCtx() {
        // we don't have context-sensitive help for this action
        return HelpCtx.DEFAULT_HELP;
    }
    
    protected boolean asynchronous() {
        // it doesn't take long to add a new item, so it's safe to run this
        // event-dispatching thread.  If we had a long-running operation, we
        // might want to run it in a separate thread by setting this value to
        // true, but make sure all GUI updates to the are done in the 
        // event-dispatching thread.  See org.openide.util.AsyncGUIJob and/or
        // org.openide.util.Mutex for classes you might use to do this, and
        // then search the NetBeans IDE source code for examples that use them.
        return false;
    }
    
    /** 
     * determines whether this action is enabled, based on the state of the 
     * currently selected nodes 
     */
    protected boolean enable(Node[] activatedNodes) {
        // this action is enabled only when exactly one node is selected
        if (activatedNodes == null || activatedNodes.length != 1) {
            return false;
        }
        
        // ...and that node's lookup contains a valid TodoList to which we can 
        // add an item.
        Lookup nodeLookup = activatedNodes[0].getLookup();
        
        
        
//        return (nodeLookup != null);
//        return nodeLookup.lookup(Report.class) != null;
        return true;
    }
}
